package com.xunjing.test.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xunjing.common.core.utils.poi.ExcelUtil;
import com.xunjing.common.core.web.controller.BaseController;
import com.xunjing.common.core.web.domain.AjaxResult;
import com.xunjing.common.core.web.domain.MyBaseEntity;
import com.xunjing.common.core.web.page.TableDataInfo;
import com.xunjing.common.log.annotation.Log;
import com.xunjing.common.log.enums.BusinessType;
import com.xunjing.common.security.annotation.RequiresPermissions;
import com.xunjing.test.domain.SoOrders;
import com.xunjing.test.service.ISoOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * 订单测试Controller
 *
 * @author zhangyt
 * @date 2024-04-01
 */
@RestController
@RequestMapping("/orders")
public class SoOrdersController extends BaseController {
    @Autowired
    private ISoOrdersService soOrdersService;
    private Set<String> availableTargetNames=new HashSet<>();

/*    public void setAvailableTargetNames(Set<String> availableTargetNames) {
        this.availableTargetNames = availableTargetNames;
    }*/

    /**
     * 查询订单测试列表
     */
    @RequiresPermissions("order:orders:list")
    @GetMapping("/list")
    public TableDataInfo list(SoOrders soOrders) {
        startPage();

        System.out.println("huancu"+ JSON.toJSONString(availableTargetNames));
        availableTargetNames.add("2023"+System.currentTimeMillis());
       // soOrders.setFlag("202404");
       //  List<SoOrders> list = soOrdersService.selectSoOrdersList(soOrders);
        LambdaQueryWrapper<SoOrders> wrapper = new LambdaQueryWrapper<>();
        //wrapper.eq(SoOrders::getFlag,"202404");
        wrapper.between(SoOrders::getFlag, "202312","202404");
        wrapper.ge(MyBaseEntity::getCreateTime,"2024-04-01 00:00:00");
        wrapper.le(MyBaseEntity::getCreateTime,"2024-04-02 23:59:59");
        List<SoOrders> list = soOrdersService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出订单测试列表
     */
    @RequiresPermissions("order:orders:export")
    @Log(title = "订单测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SoOrders soOrders) {
        List<SoOrders> list = soOrdersService.selectSoOrdersList(soOrders);
        ExcelUtil<SoOrders> util = new ExcelUtil<SoOrders>(SoOrders.class);
        util.exportExcel(response, list, "订单测试数据");
    }

    /**
     * 获取订单测试详细信息
     */
    @RequiresPermissions("order:orders:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(soOrdersService.getById(id));
    }

    /**
     * 新增订单测试
     */
    @RequiresPermissions("order:orders:add")
    @Log(title = "订单测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoOrders soOrders) {
        return toAjax(soOrdersService.save(soOrders));
    }

    /**
     * 修改订单测试
     */
    @RequiresPermissions("order:orders:edit")
    @Log(title = "订单测试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoOrders soOrders) {
        return toAjax(soOrdersService.updateById(soOrders));
    }

    /**
     * 删除订单测试
     */
    @RequiresPermissions("order:orders:remove")
    @Log(title = "订单测试", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(soOrdersService.removeByIds(Arrays.asList(ids)));
    }
}
